package cc.dong.servlet;

import cc.dong.entity.Employee;
import cc.dong.service.PunchClockService;
import cc.dong.service.impl.PunchClockServiceImpl;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Map;

/**
 * @author xiaoDong
 * @version 1.0.0
 * @ClassName PunchClockServlet.java
 * @Description 打卡servlet
 * @createTime 2024年05月31日 08:37:00
 */
@WebServlet(urlPatterns = "/punchClock.action")
public class PunchClockServlet extends HttpServlet {
    PunchClockService punchClockService = new PunchClockServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        HttpSession session = req.getSession();

        Employee employee = (Employee) session.getAttribute("employee");
        Map<String, String> map = punchClockService.punchClock(employee.getId());

        String jsonMap = JSON.toJSONString(map);
        resp.getWriter().print(jsonMap);


    }
}
